﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Manager_ListDepartment : System.Web.UI.Page
{
    CommonClass ccobj = new CommonClass();
    DBClass dbobj = new DBClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            bindgrid();
    }
    protected void bindgrid()
    {
        string strsql = "select * from Department";
        DataTable dt = dbobj.GetDataSet(strsql, "tabdepartment");
        GridView1.DataSource = dt.DefaultView;
        GridView1.DataKeyNames = new string[] { "DepartmentID" };
        GridView1.DataBind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bindgrid();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bindgrid();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string strsql = "update Department set DepartmentName='" + ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text + "' where DepartmentID='" + GridView1.DataKeys[e.RowIndex].Value.ToString().Trim() + "'";
        dbobj.ExecNonQuery(strsql);
        GridView1.EditIndex = -1;
        bindgrid();
    }
}